<?php
    
    
    include_once "include/constants.php";
	
    if (!defined('IS_AJAX')) {
        define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
    }
function getMovieFullData() {
    try {
        $conn = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         
        $stmt = $conn->prepare('select * from movies order by title;');
		$stmt->execute();
        
        $movie_list = array();
        while ($movie_row = $stmt->fetch()) {
            $movie_list[$movie_row["title"]] = $movie_row;
        }
        
        echo "<script>movieFullData = " . json_encode($movie_list) . "</script>";
        
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
}

function getMovieTitles() {
    try {
        $conn = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         
        $stmt = $conn->prepare('select * from movies order by title;');
		$stmt->execute();
        
        $movie_list = array();
        while ($movie_row = $stmt->fetch()) {
            $movie_list[] = $movie_row["title"];
        }
        
        echo "<script>movieTitles = " . json_encode($movie_list) . "</script>";
        
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
}


    
?>